<!--相关方调查评价-->

<template>
  <div>
    <div :bordered="false" style="over-flow:scroll">
      <div>
        <a-row>
          <div class="table-operator">
            <a-row>
              <a-col :md="24" :sm="24">
                <a-button   v-if="type=='add' || type=='edit'|| type=='share'"  type="primary" :disabled="type=='view'"   @click="goAdd()">新增相关方调查</a-button>
                <a-button   v-if="type=='add' || type=='edit'|| type=='share'"  type="info"  :disabled="type=='view' || groupList.length == 0"  @click="goDel()">删除</a-button>
              </a-col>
            </a-row>
          </div>
          
          
          <a-table
                  :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
                  :columns="columns" bordered
                  :data-source="groupList">
            
            <span slot="serial" slot-scope="text, record, index">{{ index + 1 }}</span>
            
            <span slot="action" slot-scope="text, record">
                  <template>
                  <a   v-if="type=='add' || type=='edit'|| type=='share'"  @click="handleEdit(record)">编辑</a>
                  </template>
                </span>
          </a-table>
        </a-row>
      </div>
    </div>
    <a-modal width="1000px" v-model="visible"  :confirm-loading="confirmLoading" :title="title" >
      <template slot="footer">
        <a-button key="back" @click="handleCancel">
          取消
        </a-button>
        <a-button :disabled="type=='view'"  key="submit" type="primary" :loading="loading" @click="handleOk">
          确定
        </a-button>
      </template>
      <a-form :model="form">
        <a-row>
          <a-col :md="12" :sm="12">
            <a-form-item
                    label="单位名称"
                    :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                    :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
              <BaseInput :disabled="type=='view'"  v-model="form.name"  placeholder="请输入"  :maxLength="30" />
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="12">
            <a-form-item
                    label="评价人姓名/职务/电话"
                    :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                    :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
              <BaseInput :disabled="type=='view'"  v-model="form.nameAndPhone" placeholder="请输入" :maxLength="30"  />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :md="12" :sm="12">
            <a-form-item
                    label="调查方式"
                    :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                    :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
              <BaseInput :disabled="type=='view'"  v-model="form.investigationType" :maxLength="30" 
                       placeholder="请输入" />
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="12">
            <a-form-item
                    label="评价结果"
                    :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                    :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
              <BaseInput :disabled="type=='view'"  v-model="form.evaluationEffect"  placeholder="请输入"  :maxLength="30" />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-modal>
  </div>
</template>

<script>
  import { STable } from '@/components'
  import { getInvestigationList ,addInvestigationList ,editInvestigationList, deleteInvestigationList} from '@/api/subcontractors/labour'

  const columns = [
    {
      title: '序号',
      width:65,
      scopedSlots: { customRender: 'serial' }
    },
    {
      title: '单位名称',
      dataIndex: 'name',
      ellipsis: true,
    },
    {
      title: '评价人姓名/职务/电话',
      dataIndex: 'nameAndPhone',
      ellipsis: true,
    },
    {
      title: '调查方式',
      dataIndex: 'investigationType',
      ellipsis: true,
    },
    {
      title: '评价结果',
      dataIndex: 'evaluationEffect',
      ellipsis: true,
    },
    {
      title: '操作',
      dataIndex: 'action',
      width: '150px',
      scopedSlots: { customRender: 'action' }
    }
  ]
  export default {
  name:'a'+Date.now(),
    props: {
      labourList: {
        type: [Object, Array],
        default() {
          return {}
        }
      }
    },
    data(){
      this.columns = columns
      return{
        visible:false,
        type:'',
        disabled:false,
        id:'',
        confirmLoading:false,
        subcontractorId:1,
        title:'',
        loading:false,
        form:{
          name:'',
          nameAndPhone:'',
          investigationType:'',
          evaluate:'',
        },
        groupList:[],
        selectedRowKeys:[],
        selectedRows:[],
        selectId:[],
        addInvestigateId:''
      }
    },
    created() {
      this.addInvestigateId = JSON.parse(sessionStorage.getItem("addInvestigateId"))
      this.type=this.$route.query.type
      if(this.type == 'share'){
        this.id = this.addInvestigateId
      }else{
        this.id = this.$route.query.id || this.addInvestigateId
      }
      this.getGroup()
    },
    methods:{
      onSelectChange(selectedRowKeys,selectedRows) {
        console.log('selectedRows: ', selectedRows);
        console.log('selectedRowKeys changed: ', selectedRowKeys);
        this.selectedRowKeys = selectedRowKeys;
        this.selectedRows = selectedRows
      },
      getGroup(){
        getInvestigationList({id:this.id}).then((res)=>{
          this.groupList=res.data
        })
      },
      search(){
        this.$refs.table.refresh(true)
      },
      goAdd(){
        this.form={}
        this.visible=true
        this.title='新增相关方调查评价'
      },
      goDel(){
        let _this = this
        if(_this.selectedRows.length==1){

          this.$confirm({
            title: '警告提醒！',
            content: '确定删除？',
            okType: 'danger',
            onOk() {
              _this.confirmLoading=true
              deleteInvestigationList({ids:_this.selectedRows[0].id,lsebId:_this.labourList.subcontractorBase.evaluationId}).then((res)=>{
                if(res.code=='200'){
                  _this.getGroup()
                  _this.confirmLoading=false
                  _this.$message.success("删除成功")
                  _this.selectedRows=[]
                  _this.selectedRowKeys=[]
                }
              }).catch(()=>{_this.confirmLoading=false})
            },
            onCancel() {
              console.log('Cancel');
            },
          });
        }else if(_this.selectedRows.length>1){
          _this.selectId=[]
          _this.selectedRows.forEach((item)=>{
            _this.selectId.push(item.id)
          })
          _this.$confirm({
            title: '警告提醒！',
            content: '确定删除？',
            okType: 'danger',
            onOk() {
              _this.confirmLoading=true
              deleteInvestigationList({ids:_this.selectId.join(","),lsebId:_this.labourList.subcontractorBase.evaluationId}).then((res)=>{
                if(res.code=='200'){
                  _this.getGroup()
                  _this.confirmLoading=false
                  _this.$message.success("删除成功")
                  _this.selectedRows=[]
                  _this.selectedRowKeys=[]
                }
              }).catch(()=>{_this.confirmLoading=false})
            },
            onCancel() {
              console.log('Cancel');
            },
          });
        }else if(_this.selectedRows.length == 0){
			_this.$message.error("请选择要删除的内容")
		}
      },
      handleSub(){

      },
      handleEdit(record){
        this.visible = true
        this.title='编辑相关方调查评价'
        // this.form = record
		this.form = JSON.parse(JSON.stringify(record))

      },
      handleOk(){
        this.visible = false
        this.form.lsebId = this.labourList.subcontractorBase.evaluationId
        if(this.form.id){
          editInvestigationList(this.form).then((res)=>{
            if(res.code=='200'){
              this.$message.success("编辑成功")
              this.getGroup()
            }
          }).catch(()=>{console.log("失败")})
        }else{
          addInvestigationList(this.form).then((res)=>{
            if(res.code=='200'){
              this.$message.success("新增成功")
              this.getGroup()
            }
          }).catch(()=>{console.log("失败")})
        }
      },
      handleCancel(){
        this.visible = false
      },
      handleAdd(){

      }
    }
  }
</script>

<style scoped>
  .input{
    width:100%
  }
  /deep/ .ant-table-pagination.ant-pagination{
    display:none
  }
</style>
